// Copyright 2008 FriendFeed
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License. You may obtain
// a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.

namespace FriendFeed
{
    using System;
    using System.Collections.Generic;
    using System.Xml;

    public class Entry
    {
        public List<Comment> Comments;
        public string Id;
        public List<Like> Likes;
        public string Link;
        public List<Media> Media;
        public DateTime Published;
        public Service Service;
        public string Title;
        public DateTime Updated;
        public User User;

        public Entry(XmlElement element)
        {
            Id = Util.ChildValue(element, "id");
            Title = Util.ChildValue(element, "title");
            Link = Util.ChildValue(element, "link");
            Published = DateTime.Parse(Util.ChildValue(element, "published"));
            Updated = DateTime.Parse(Util.ChildValue(element, "updated"));
            User = new User(Util.ChildElement(element, "user"));
            Service = new Service(Util.ChildElement(element, "service"));
            Comments = new List<Comment>();
            foreach (XmlElement child in element.GetElementsByTagName("comment"))
            {
                Comments.Add(new Comment(child));
            }
            Likes = new List<Like>();
            foreach (XmlElement child in element.GetElementsByTagName("like"))
            {
                Likes.Add(new Like(child));
            }
            Media = new List<Media>();
            foreach (XmlElement child in element.GetElementsByTagName("media"))
            {
                Media.Add(new Media(child));
            }
        }
    }
}